/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "StockCode")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "StockCode.findAll", query = "SELECT s FROM StockCode s"),
    @NamedQuery(name = "StockCode.findByStockID", query = "SELECT s FROM StockCode s WHERE s.stockID = :stockID"),
    @NamedQuery(name = "StockCode.findByTableID", query = "SELECT s FROM StockCode s WHERE s.tableID = :tableID"),
    @NamedQuery(name = "StockCode.findByTblIDAndWHID", query = "SELECT s FROM StockCode s WHERE s.tableID = ?1 and s.whid.wearhouseID = ?2"),
    @NamedQuery(name = "StockCode.findAllMalt", query = "SELECT s FROM StockCode s WHERE s.whid.wearhouseID = '100'")})
public class StockCode implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "StockID")
    private Integer stockID;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TableID")
    private int tableID;
    @JoinColumn(name = "WHID", referencedColumnName = "WearhouseID")
    @ManyToOne(optional = false)
    private Wearhouse whid;
    @JoinColumn(name = "StockVendID", referencedColumnName = "VID", nullable=true)
    @ManyToOne(optional = true)
    private Vendors stockVendID;
    @JoinColumn(name = "StockAltVendID", referencedColumnName = "VID", nullable=true)
    @ManyToOne(optional = true)
    private Vendors stockAltVendID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "polpn")
    private Collection<POLines> poLinesCollection;

    public StockCode() {
    }

    public StockCode(Integer stockID) {
        this.stockID = stockID;
    }

    public StockCode(Integer stockID, int tableID) {
        this.stockID = stockID;
        this.tableID = tableID;
    }

    public Integer getStockID() {
        return stockID;
    }

    public void setStockID(Integer stockID) {
        this.stockID = stockID;
    }

    public int getTableID() {
        return tableID;
    }

    public void setTableID(int tableID) {
        this.tableID = tableID;
    }

    public Wearhouse getWhid() {
        return whid;
    }

    public void setWhid(Wearhouse whid) {
        this.whid = whid;
    }

    public Vendors getStockVendID() {
        return stockVendID;
    }

    public void setStockVendID(Vendors stockVendID) {
        if(stockVendID != null && stockVendID.getVid() != null){
            this.stockVendID = stockVendID;
        }
    }

    public Vendors getStockAltVendID() {
        return stockAltVendID;
    }

    public void setStockAltVendID(Vendors stockAltVendID) {
        if(stockAltVendID != null && stockAltVendID.getVid() != null){
            this.stockAltVendID = stockAltVendID;
        }
    }

    @XmlTransient
    public Collection<POLines> getPOLinesCollection() {
        return poLinesCollection;
    }

    public void setPOLinesCollection(Collection<POLines> poLinesCollection) {
        this.poLinesCollection = poLinesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (stockID != null ? stockID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof StockCode)) {
            return false;
        }
        StockCode other = (StockCode) object;
        if ((this.stockID == null && other.stockID != null) || (this.stockID != null && !this.stockID.equals(other.stockID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.StockCode[ stockID=" + stockID + " ]";
    }
    
}
